<template>
	<view>
		<!-- 账号管理 -->
		<card v-if="loginStatus" headTitle="账号管理" bodyStyle="background:#ffffff;">
			<uni-list-item 
				title="个人资料" 
				showArrow 
				@click="navigate('user-userinfo')"
			></uni-list-item>
			<uni-list-item 
				title="收货地址" 
				showArrow 
				@click="navigate('address-list')"
			></uni-list-item>
			<uni-list-item 
				title="修改密码" 
				showArrow 
				@click="navigate('change-password')"
			></uni-list-item>
			<uni-list-item 
				title="绑定手机号" 
				showArrow 
				@click="navigate('bind-phone')"
			></uni-list-item>
		</card>

		<!-- 关于 -->
		<card headTitle="关于" bodyStyle="background:#ffffff;">
			<uni-list-item 
				v-for="(item, index) in aboutList" 
				:key="index" 
				:title="item.title" 
				showArrow 
				@click="navigate(item.path)"
			></uni-list-item>
		</card>

		<!-- 退出登录 -->
		<view class="p-3" v-if="loginStatus">
			<button type="default" class="bg-white" @click="logoutEvent">退出登录</button>
		</view>
	</view>
</template>
<script>
	import card from "@/components/common/card.vue";

	import uniListItem from '@/components/uni-ui/uni-list-item/uni-list-item.vue';

	export default {
		components: {
			card,
			uniListItem
		},
		data() {
			return {
				loginStatus: true, // 模拟登录状态
				aboutList: [
					{ title: "关于商城", path: "about" },
					{ title: "意见反馈", path: "feedback" },
					{ title: "协议规则", path: "agreement" },
					{ title: "资质证件", path: "credentials" },
					{ title: "用户协议", path: "user-agreement" },
					{ title: "隐私政策", path: "privacy-policy" }
				]
			};
		},
		methods: {
			navigate(path) {
				if (!path) return;
				uni.navigateTo({
					url: `/pages/${path}/${path}`
				});
			},
			logoutEvent() {
				// 模拟退出登录接口请求
				this.$H.post('/logout', {}, {
					token: false,
					toast: false
				}).then(() => {
					// 清除登录状态
					this.loginStatus = false;
					uni.showToast({
						title: '退出成功',
						icon: 'none'
					});
					uni.navigateBack({
						delta: 1
					});
				}).catch(err => {
					console.error('退出登录失败:', err);
					uni.showToast({
						title: '退出失败，请重试',
						icon: 'none'
					});
				});
			}
		}
	};
</script>

<style>
	page {
		background: #EEEEEE;
	}

	.p-3 {
		padding: 20rpx;
	}

	button.bg-white {
		background-color: #FFFFFF;
		color: #333333;
		border: 1px solid #DDDDDD;
		border-radius: 50rpx;
		font-size: 32rpx;
		height: 80rpx;
		line-height: 80rpx;
	}
</style>